package com.tmz.cloudmall.cloudmallgateway.config;

/**
 * @ClassName NacosConfigChecker
 * @Description 这里填写类的功能描述
 * @Author tmz
 * @Date 2025/9/1
 */
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Configuration;
import javax.annotation.PostConstruct;

// @RefreshScope 支持配置动态刷新
@RefreshScope
@Configuration
@Slf4j
public class NacosConfigChecker {

    // 注入 Nacos 中配置的路由相关属性（根据实际配置的 key 调整）
    @Value("${spring.cloud.gateway.routes[3].id:未读取到配置}")
    private String firstRouteId;

    @Value("${spring.cloud.gateway.routes[3].uri:未读取到配置}")
    private String firstRouteUri;
    @Value("${spring.cloud.gateway.routes[3].predicates[0]:未读取到配置}")
    private String firstPredicates;

    @Value("${spring.application.name:未读取到配置}")
    private String serverName;

    // 启动时打印配置
    @PostConstruct
    public void printNacosConfig() {
        log.info("===== 从 Nacos 读取的配置 =====");
        log.info(serverName);
        log.info("第4条路由 ID：" + firstRouteId);
        log.info("第4条路由 URI：" + firstRouteUri);
        log.info("第4条路由断言：" + firstPredicates);
        log.info("===========================");
    }
}
